package com.ruantu.clothing.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruantu.clothing.dao.PermissionDao;
import com.ruantu.clothing.dao.RolePerDao;
import com.ruantu.clothing.entity.Permission;
import com.ruantu.clothing.service.PermissionService;

@Service
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionDao permissionDao;
    @Autowired
    private RolePerDao rpDao;
    ;

    @Override
    public List<Permission> findAll() {

        return permissionDao.getAll();
    }

    /***
     * 根据角色得到该角色的权限列表
     */
    @Override
    public Map<String, Object> getOneRolePer(int roleid) {
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            List<Permission> pList = permissionDao.getAll();
            List<Integer> rolePerList = rpDao.findAllPermissionId(roleid);
            map.put("pList", pList);
            map.put("rolePerList", rolePerList);
            return map;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

}
